package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.eggs.*;
import com.yanqu.road.pb.eggs.EggsActivityProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.eggs.EggsActivityConfig;

import java.util.Map;

public class EggsActivityPb {
    public static EggsActivityProto.EggsSceneConfigTempMsg.Builder parseEggsSceneConfigTempMsg(EggsSceneConfig data, String language){
        if(null == data){
            return null;
        }
        EggsActivityProto.EggsSceneConfigTempMsg.Builder msg = EggsActivityProto.EggsSceneConfigTempMsg.newBuilder();
        msg.setEventId(data.getEventId());
        msg.setType(data.getType());
        msg.setDesc(ServerLanguageMgr.getContent(data.getDesc(), language));
        msg.setWeight(data.getWeight());
        msg.setConsume(data.getConsume());
        msg.setReward(data.getReward());
        msg.setExtendParam(data.getExtendParam());
        return msg;
    }

    public static EggsActivityProto.EggsClassRoomConfigTempMsg.Builder parseEggsClassRoomConfigTempMsg(EggsClassRoomConfig data, String language){
        if(null == data){
            return null;
        }
        EggsActivityProto.EggsClassRoomConfigTempMsg.Builder msg = EggsActivityProto.EggsClassRoomConfigTempMsg.newBuilder();
        msg .setId(data.getId());
        msg.setTitle(ServerLanguageMgr.getContent(data.getTitle(), language));
        msg.setContent(ServerLanguageMgr.getContent(data.getContent(), language));
        msg.setPreface(ServerLanguageMgr.getContent(data.getPreface(), language));
        msg.setKeyExp(ServerLanguageMgr.getContent(data.getKeyExp(), language));
        msg.setWordAnalysis(ServerLanguageMgr.getContent(data.getWordAnalysis(), language));
        msg.setTest(ServerLanguageMgr.getContent(data.getTest(), language));
        msg.setRewards(data.getRewards());
        return msg;
    }

    public static EggsActivityProto.EggsTestConfigTempMsg.Builder parseEggsTestConfigTempMsg(EggsTestConfig data, String language){
        if(null == data){
            return null;
        }
        EggsActivityProto.EggsTestConfigTempMsg.Builder msg = EggsActivityProto.EggsTestConfigTempMsg.newBuilder();
        msg.setId(data.getId());
        msg.setDesc(ServerLanguageMgr.getContent(data.getDesc(), language));
        return msg;
    }

    public static EggsActivityProto.EggsSongConfigTempMsg.Builder parseEggsSongConfigTempMsg(EggsSongConfig data, String language){
        if(null == data){
            return null;
        }
        EggsActivityProto.EggsSongConfigTempMsg.Builder msg = EggsActivityProto.EggsSongConfigTempMsg.newBuilder();
        msg.setId(data.getId());
        msg.setIcon(data.getIcon());
        msg.setName(ServerLanguageMgr.getContent(data.getName(), language));
        msg.setDesc(ServerLanguageMgr.getContent(data.getDesc(), language));
        msg.setRewards(data.getRewards());
        return msg;
    }

    public static EggsActivityProto.EggsStoryConfigTempMsg.Builder parseEggsStoryConfigTempMsg(EggsStoryConfig data, String language){
        if(null == data){
            return null;
        }
        EggsActivityProto.EggsStoryConfigTempMsg.Builder msg = EggsActivityProto.EggsStoryConfigTempMsg.newBuilder();
        msg.setId(data.getId());
        msg.setIcon(data.getIcon());
        msg.setTab(data.getTab());
        msg.setDesc(ServerLanguageMgr.getContent(data.getDesc(), language));
        msg.setContent(ServerLanguageMgr.getContent(data.getContent(), language));
        msg.setRewards(data.getRewards());
        return msg;
    }

    public static EggsActivityProto.EggsSyncConfigMsg.Builder parseEggsSyncConfigMsg(int activityId, String language,
                                                                                     Map<Integer, EggsClassRoomConfig> classRoomConfigMap,
                                                                                     Map<Integer, EggsTestConfig> testConfigMap,
                                                                                     Map<Integer, EggsSongConfig> songConfigMap,
                                                                                     Map<Integer, EggsStoryConfig> storyConfigMap,
                                                                                     Map<Integer, EggsSceneConfig> sceneConfigMap){
        EggsActivityProto.EggsSyncConfigMsg.Builder syncMsg = EggsActivityProto.EggsSyncConfigMsg.newBuilder();
        syncMsg.setActivityId(activityId);
        if(null != classRoomConfigMap){
            for(EggsClassRoomConfig data : classRoomConfigMap.values()){
                EggsActivityProto.EggsClassRoomConfigTempMsg.Builder msg = parseEggsClassRoomConfigTempMsg(data, language);
                if(null != msg){
                    syncMsg.addClassRoomList(msg);
                }
            }
        }
        if(null != testConfigMap){
            for(EggsTestConfig data : testConfigMap.values()){
                EggsActivityProto.EggsTestConfigTempMsg.Builder msg = parseEggsTestConfigTempMsg(data, language);
                if(null != msg){
                    syncMsg.addTestList(msg);
                }
            }
        }
        if(null != songConfigMap){
            for(EggsSongConfig data : songConfigMap.values()){
                EggsActivityProto.EggsSongConfigTempMsg.Builder msg = parseEggsSongConfigTempMsg(data, language);
                if(null != msg){
                    syncMsg.addSongList(msg);
                }
            }
        }
        if(null != storyConfigMap){
            for(EggsStoryConfig data : storyConfigMap.values()){
                EggsActivityProto.EggsStoryConfigTempMsg.Builder msg = parseEggsStoryConfigTempMsg(data, language);
                if(null != msg){
                    syncMsg.addStoryList(msg);
                }
            }
        }
        if(null != sceneConfigMap){
            for(EggsSceneConfig data : sceneConfigMap.values()){
                EggsActivityProto.EggsSceneConfigTempMsg.Builder msg = parseEggsSceneConfigTempMsg(data, language);
                if(null != msg){
                    syncMsg.addSceneList(msg);
                }
            }
        }
        return syncMsg;
    }

    public static EggsActivityProto.EggsSyncConfigMsg.Builder parseEggsSyncConfigMsg(EggsActivityConfig eggsActivityConfig, String language){
        if(null == eggsActivityConfig){
            return null;
        }
        return parseEggsSyncConfigMsg(eggsActivityConfig.getActivityId(), language, eggsActivityConfig.getClassRoomConfigMap(),
                eggsActivityConfig.getTestConfigMap(), eggsActivityConfig.getSongConfigMap(), eggsActivityConfig.getStoryConfigMap(),
                eggsActivityConfig.getSceneConfigMap());
    }

    public static EggsActivityProto.EggsClassRoomDataTempMsg.Builder parseEggsClassRoomDataTempMsg(EggsClassRoomData classRoomData){
        if(null == classRoomData){
            return null;
        }
        EggsActivityProto.EggsClassRoomDataTempMsg.Builder msg = EggsActivityProto.EggsClassRoomDataTempMsg.newBuilder();
        msg.setId(classRoomData.getId());
        msg.setIsReward(classRoomData.isReward());
        return msg;
    }

    public static EggsActivityProto.EggsTestDataTempMsg.Builder parseEggsTestDataTempMsg(EggsTestData testData){
        if(null == testData){
            return null;
        }
        EggsActivityProto.EggsTestDataTempMsg.Builder msg = EggsActivityProto.EggsTestDataTempMsg.newBuilder();
        msg.setId(testData.getId());
        msg.setChoose(testData.getChoose());
        return msg;
    }

    public static EggsActivityProto.EggsSongDataTempMsg.Builder parseEggsSongDataTempMsg(EggsSongData songData){
        if(null == songData){
            return null;
        }
        EggsActivityProto.EggsSongDataTempMsg.Builder msg = EggsActivityProto.EggsSongDataTempMsg.newBuilder();
        msg.setId(songData.getId());
        msg.setIsReward(songData.isReward());
        return msg;
    }

    public static EggsActivityProto.EggsStoryDataTempMsg.Builder parseEggsStoryDataTempMsg(EggsStoryData storyData){
        if(null == storyData){
            return null;
        }
        EggsActivityProto.EggsStoryDataTempMsg.Builder msg = EggsActivityProto.EggsStoryDataTempMsg.newBuilder();
        msg.setId(storyData.getId());
        msg.setIsReward(storyData.isReward());
        return msg;
    }

    public static EggsActivityProto.EggsUserDataMsg.Builder parseEggsUserDataMsg(EggsUserData eggsUserData){
        if(null == eggsUserData){
            return null;
        }
        EggsActivityProto.EggsUserDataMsg.Builder dataMsg = EggsActivityProto.EggsUserDataMsg.newBuilder();
        dataMsg.setActivityId(eggsUserData.getActivityId());
        dataMsg.setTestId(eggsUserData.getCurTestId());
        if(null != eggsUserData.getClassRoomDataMap()){
            for(EggsClassRoomData data : eggsUserData.getClassRoomDataMap().values()){
                EggsActivityProto.EggsClassRoomDataTempMsg.Builder msg = parseEggsClassRoomDataTempMsg(data);
                if(null != msg){
                    dataMsg.addClassRoomDataList(msg);
                }
            }
        }
        if(null != eggsUserData.getTestDataMap()){
            for(EggsTestData data : eggsUserData.getTestDataMap().values()){
                EggsActivityProto.EggsTestDataTempMsg.Builder msg = parseEggsTestDataTempMsg(data);
                if(null != msg){
                    dataMsg.addTestDataList(msg);
                }
            }
        }
        if(null != eggsUserData.getSongDataMap()){
            for(EggsSongData data : eggsUserData.getSongDataMap().values()){
                EggsActivityProto.EggsSongDataTempMsg.Builder msg = parseEggsSongDataTempMsg(data);
                if(null != msg){
                    dataMsg.addSongDataList(msg);
                }
            }
        }
        if(null != eggsUserData.getStoryDataMap()){
            for(EggsStoryData data : eggsUserData.getStoryDataMap().values()){
                EggsActivityProto.EggsStoryDataTempMsg.Builder msg = parseEggsStoryDataTempMsg(data);
                if(null != msg){
                    dataMsg.addStoryDataList(msg);
                }
            }
        }
        return dataMsg;
    }
}
